package com.egdigital.allzic.ui.fragment;

import android.app.Activity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.actionbarsherlock.app.SherlockFragment;
import com.egdigital.allzic.R;
import com.egdigital.allzic.ui.activity.ActivityTuto;
import com.egdigital.allzic.utils.ImageManager;
import com.egdigital.allzic.utils.Utils;

public class FragmentTutoPage extends SherlockFragment implements OnClickListener {

	private static final String	TAG		= FragmentTutoPage.class.getSimpleName();	// log
	private int					mImageNumber;
	private boolean				mIsLast	= false;
	private ImageManager		mImageManager;
	//
	private ImageView			mImage;
	private View				mView;

	@Override
	public void onAttach(Activity activity) {
		mImageManager = ImageManager.getInstance(activity.getApplicationContext());
		super.onAttach(activity);
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		mView = inflater.inflate(R.layout.fragment_image, container, false);
		mImage = (ImageView) mView.findViewById(R.id.fragment_page_image);
		return mView;
	}

	@Override
	public void onViewCreated(View view, Bundle savedInstanceState) {
		super.onViewCreated(view, savedInstanceState);
		Bundle bundle = this.getArguments();
		mImageNumber = bundle.getInt("name");
		mIsLast = bundle.getBoolean("is_last");
		if (mIsLast) {
			mImage.setBackgroundResource(0);
			mImage.setOnClickListener(this);
		}
		Utils.setImageFromUrl(mImageManager, "assets://gallery/intro_slide" + mImageNumber + ".png", mImage);
	}

	@Override
	public void onClick(View v) {
		((ActivityTuto) getSherlockActivity()).moveToHome(true);
	}
}
